package cn.jtool.dig.client.comm.virtual;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.timeout.IdleStateHandler;
import jakarta.annotation.Resource;
import lombok.Getter;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Getter
@Component
@ChannelHandler.Sharable
public class VirtualChannelInitializer extends ChannelInitializer<Channel> {

    @Resource
    private VirtualConnHandler virtualConnHandler;

    @Resource
    private VirtualDataHandler virtualDataHandler;
    @Resource
    private VirtualOutHander virtualOutHander;

    @Override
    protected void initChannel(Channel channel) throws Exception {
        channel.pipeline().addLast("ping", new IdleStateHandler(0, 0, 120, TimeUnit.SECONDS));
        channel.pipeline().addLast("virtualConnHandler", this.virtualConnHandler);
        channel.pipeline().addLast("virtualDataHandler", this.virtualDataHandler);
        channel.pipeline().addLast("virtualOutHander", this.virtualOutHander);
    }
}
